#include <cmath>
#include <limits>
using namespace std;
struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  TreeNode()
      : val(0), left(nullptr), right(nullptr){} * TreeNode(int x)
      : val(x),
        left(nullptr),
        right(nullptr){} * TreeNode(int x, TreeNode *left, TreeNode *right)
      : val(x),
        left(left), right(right) {}
};

void inOrder(TreeNode *root, int &minDiff, int &pre) {
  if (!root)
    return;
  inOrder(root->left, minDiff, pre);
  minDiff = min<int>(minDiff, abs(root->val - pre));
  pre = root->val;
  inOrder(root->right, minDiff, pre);
}
int getMinimumDifference(TreeNode *root) {
  int pre = numeric_limits<int>::max();
  int minDiff = numeric_limits<int>::max();
  inOrder(root, minDiff, pre);
  return minDiff;
}